package sz.szsmk.citizencard.ui.newversion.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener
import com.scwang.smart.refresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.fragment_coupon_used.*
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.bean.response.BaseBean
import sz.szsmk.citizencard.model.network.bean.response.CouponListBean
import sz.szsmk.citizencard.mvp.BasePresenter
import sz.szsmk.citizencard.ui.newversion.activity.presenter.CouponUsedPresenter
import sz.szsmk.citizencard.ui.newversion.activity.adapter.CouponListAdapter
import sz.szsmk.citizencard.ui.dzsmkfragment.AppBaseFragment
import sz.szsmk.citizencard.ui.newversion.fragment.view.ICouponUsedMvpView
import javax.inject.Inject

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 20:27
 * description:
 */
class CouponUsedFragment : AppBaseFragment(), ICouponUsedMvpView {

    @Inject
    lateinit var couponUsedPresenter: CouponUsedPresenter

    var couponListAdapter : CouponListAdapter?= null

    override fun initPresenters(): Array<BasePresenter<*>>? {
        return arrayOf(couponUsedPresenter)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val root = inflater.inflate(R.layout.fragment_coupon_used, container, false)
        component.inject(this)
        return root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        rl_coupon_used.layoutManager = LinearLayoutManager(requireContext())
        couponListAdapter = CouponListAdapter()
        rl_coupon_used.adapter = couponListAdapter
        swipeRefreshLayout.setOnRefreshListener(OnRefreshListener {
//            currentPager = 1
//            if (door == "net") {
//                //网点
//                mPresenter.sernetSeatch(keyWord, currentPager)
//            } else {
//                //商家
//                mPresenter.shopSearch(keyWord, DaggerApplication.getCurrentLocation().latitude.toString() + "", DaggerApplication.getCurrentLocation().longitude.toString() + "", currentPager)
//            }
        })
        swipeRefreshLayout.setOnLoadMoreListener(OnLoadMoreListener {
//            if (door == "net") {
//                //网点
//                mPresenter.sernetSeatch(keyWord, currentPager)
//            } else {
//                //商家
//                mPresenter.shopSearch(keyWord, DaggerApplication.getCurrentLocation().latitude.toString() + "", DaggerApplication.getCurrentLocation().longitude.toString() + "", currentPager)
//            }
        })
        var list = mutableListOf<CouponListBean.CouponBean>()
        for(index in 1..30){
            list.add(CouponListBean.CouponBean())
        }
        couponListAdapter?.setNewData(list)
        couponUsedPresenter.getUserCoupons()

    }




    override fun getTopTitle() = null

    companion object {
        val instance: CouponUsedFragment
            get() = CouponUsedFragment()
    }

    override fun getCouponCountSuccess(response: CouponListBean) {
    }

    override fun onFail(baseBean: BaseBean) {
    }
}